import org.junit.Test;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class CollectDemo {


    @Test
    public void t1(){
        LinkedList<Integer> linkedList = new LinkedList();
        linkedList.add(3);
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(5);
        linkedList.add(6);
        System.out.println(linkedList);
    }

    @Test
    public void t2(){
        // 并发安全的集合类
        CopyOnWriteArrayList<Integer> copyList = new CopyOnWriteArrayList<>();
        copyList.add(1);
        copyList.add(2);
        copyList.add(3);
        copyList.add(4);
        copyList.add(5);
        copyList.add(5);
        //   for (Integer value : copyList) {
        //       if (value == 5){
        Integer value = 5;
        boolean flag = copyList.remove(value);
        //       }
        //  }
        System.out.println(copyList);
    }

    @Test
    public void t3(){
        // 并发安全的集合类
        CopyOnWriteArrayList<Integer> copyList = new CopyOnWriteArrayList<>();
        copyList.add(1);
        copyList.add(2);
        copyList.add(3);
        copyList.add(4);
        copyList.add(5);
        copyList.add(5);
        //   for (Integer value : copyList) {
        //       if (value == 5){
        Integer value = 5;
        boolean flag = copyList.remove(Integer.valueOf(5));
        //       }
        //  }
        System.out.println(copyList);
    }

    @Test
    public void t4(){
        A a = new A("1", "张三");
        A a1 = new A("2", "李四");
        A a2 = new A("3", "李3");
        TreeSet<A> treeSet = new TreeSet<>();
        treeSet.add(a);
        treeSet.add(a1);
        treeSet.add(a2);
        System.out.println(treeSet);
    }

    @Test
    public void t5(){
        A a = new A("1", "张三");
        A a1 = new A("2", "李四");
        A a2 = new A("3", "李3");
        HashSet<A> hashSet = new HashSet<>();
        hashSet.add(a);
        hashSet.add(a1);
        hashSet.add(a2);
        System.out.println(hashSet);
    }

    @Test
    public void t6(){
        A a = new A("1", "张三");
        A a1 = new A("2", "李四");
        A a2 = new A("3", "李3");
        TreeMap<A,Integer> treeMap = new TreeMap<A,Integer>();
        treeMap.put(a,1);
        treeMap.put(a1,2);
        treeMap.put(a2,3);
        System.out.println(treeMap);
    }
    @Test
    public void t7(){
        BitSet bitSet = new BitSet();
        bitSet.set(1);
        bitSet.set(2);
        bitSet.set(2);
        bitSet.set(100);
        System.out.println(bitSet);
    }
    @Test
    public void t8(){
        A a = new A("1", "张三");
        A a1 = new A("2", "李四");
        A a2 = new A("3", "李3");
        Vector vector = new Vector<A>();
        vector.add(a);
        vector.add(a1);
        vector.add(a2);
        System.out.println(vector);
    }

    @Test
    public void t9() {
        A a = new A("1", "张三");
        A a1 = new A("2", "李四");
        A a2 = new A("3", "李3");
        ArrayList<A> list = new ArrayList<>();
        list.add(a);
        list.add(a1);
        list.add(a2);
        List<A> subList = list.subList(0, 2);
        System.out.println(subList);
    }

    @Test
    public void t10() {
        ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
        map.put("A","a");
    }
    @Test
    public void t11() {
        HashMap<String,String> map = new HashMap<>();
        map.put("A","a");
        map.put("B","b");
        map.get("A");
    }

    @Test
    public void t12() {
        // 基于跳表
        ConcurrentSkipListMap<String,String> map = new ConcurrentSkipListMap<>();
        map.put("A","a");
        map.put("B","b");
        map.get("A");
    }


    @Test
    public void t13() {
        List<String> syncList = Collections.synchronizedList(new ArrayList<>());

        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        list.add("1");

    }

}
